

import * as DevicesResponse from "./class/DevicesResponse";
import {createStore} from "vuex";
import {Device} from "./class/DevicesResponse";


const DevicesModule = {
    namespaced: true,
    state: {
        devices: [],
        currDeviceIndex: 0
    },
    mutations: {
        updateDevicesList(state: any, devices: DevicesResponse.Device[]) {
            state.devices = devices;
        },
        switchFocusDevice(state: any, deviceIndex: Number) {
            state.currDeviceIndex = deviceIndex;
        }
    },
    getters: {
        getCurrDevice(state: any) : DevicesResponse.Device {
            return state.devices[state.currDeviceIndex];
        },
        getDevices(state: any) : DevicesResponse.Device[] {
            return state.devices;
        }
    }
}

const store = createStore({
    modules: {
        Devices: DevicesModule
    }
});

export default store
